# -*- python -*-
#
# BuildBot script for QuarkPlayer
#

config = BuildmasterConfig = {}


####### BUILDSLAVES

# x86 means x86-32 or i386, see http://en.wikipedia.org/wiki/X86
# x64 means x86-64 or amd64, see http://en.wikipedia.org/wiki/X64
# x86 and x64 are the denominations used by Microsoft

from buildbot.buildslave import BuildSlave
config['slaves'] = [
	BuildSlave('linux-x86', 'password'),
	BuildSlave('linux-x64', 'password'),
	BuildSlave('windows-x86', 'password'),
	BuildSlave('windows-x64', 'password')
]

config['slavePortnum'] = 9989


####### CHANGESOURCES

from buildbot.changes.svnpoller import SVNPoller
config['change_source'] = SVNPoller('http://phonon-vlc-mplayer.googlecode.com/svn/trunk/')


####### SCHEDULERS

from buildbot.scheduler import Scheduler, Nightly
build_nightly = Nightly(
	name = 'nightly',
	hour = 6,
	minute = 0,
	builderNames = [
#		'linux_x86_trunk_debug',
		'linux_x86_trunk_release',
#		'windows_x86_trunk_mingw_debug',
		'windows_x86_trunk_mingw_release',
#		'windows_x86_trunk_msvc71_debug',
		'windows_x86_trunk_msvc71_release',
#		'windows_x86_trunk_msvc90_debug',
		'windows_x86_trunk_msvc90_release'
	]
)

config['schedulers'] = [build_nightly]


####### BUILDERS

from buildbot.process import factory
from buildbot.steps.source import SVN
from buildbot.steps.shell import Configure, Compile, ShellCommand
from buildbot.steps.transfer import FileDownload, DirectoryUpload
from buildbot.steps.master import MasterShellCommand

quarkplayer_builddir = 'build/build'

checkout = SVN(svnurl = 'http://phonon-vlc-mplayer.googlecode.com/svn/trunk/')

svn_revert = ShellCommand(command = 'svn revert -R *', workdir = 'build',
		description = 'svn revert', descriptionDone = 'svn revert')

def cleanup(commandline):
	return ShellCommand(command = commandline, workdir = quarkplayer_builddir,
		description = 'cleaning', descriptionDone = 'cleanup')

def configure(commandline):
	return Configure(command = commandline, workdir = quarkplayer_builddir)

def compile(commandline):
	return Compile(command = commandline, workdir = quarkplayer_builddir)

def create_rpm(commandline):
	return ShellCommand(command = commandline, workdir = quarkplayer_builddir,
		description = 'creating rpm', descriptionDone = 'create rpm')

def create_deb(commandline):
	return ShellCommand(command = commandline, workdir = quarkplayer_builddir,
		description = 'creating deb', descriptionDone = 'create deb')

def create_nsis_setup(commandline):
	return ShellCommand(command = commandline, workdir = quarkplayer_builddir,
		description = 'creating NSIS setup', descriptionDone = 'create NSIS setup')

# Buildbot >= 0.7.10 is required for this syntax
upload_package = [
	FileDownload(mastersrc = 'login.txt', slavedest = 'login.txt', workdir = quarkplayer_builddir),
	FileDownload(mastersrc = 'upload_package.py', slavedest = 'upload_package.py', workdir = quarkplayer_builddir),
	ShellCommand(command = 'python upload_package.py \'*.exe\' \'*.deb\' \'*.rpm\'', workdir = quarkplayer_builddir,
		description = 'uploading package', descriptionDone = 'upload package')
]

create_doc = [
	ShellCommand(command = 'doxygen', workdir = 'build',
		description = 'creating doc', descriptionDone = 'create doc'),
	DirectoryUpload(slavesrc = 'doc/html', masterdest = '/var/www/doxygen', workdir = 'build'),
	MasterShellCommand(command = 'chmod a+r -R /var/www/doxygen')
]


linux_x86_trunk_debug = factory.BuildFactory()
linux_x86_trunk_debug.addStep(svn_revert)
linux_x86_trunk_debug.addStep(checkout)
linux_x86_trunk_debug.addStep(configure('./build_make-debug.sh'))
linux_x86_trunk_debug.addStep(compile('make install'))
linux_x86_trunk_debug.addStep(create_deb('make deb'))
linux_x86_trunk_debug.addStep(create_rpm('make rpm'))
linux_x86_trunk_debug.addSteps(upload_package)
builder_linux_x86_trunk_debug = {
	'name': 'linux_x86_trunk_debug',
	'slavename': 'linux-x86',
	'builddir': 'linux_x86_trunk_debug',
	'factory': linux_x86_trunk_debug,
}

linux_x86_trunk_release = factory.BuildFactory()
linux_x86_trunk_release.addStep(cleanup('make clean'))
linux_x86_trunk_release.addStep(svn_revert)
linux_x86_trunk_release.addStep(checkout)
linux_x86_trunk_release.addSteps(create_doc)
linux_x86_trunk_release.addStep(configure('./build_make-release.sh'))
linux_x86_trunk_release.addStep(compile('make install'))
linux_x86_trunk_release.addStep(create_deb('make deb'))
linux_x86_trunk_release.addStep(create_rpm('make rpm'))
linux_x86_trunk_release.addSteps(upload_package)
builder_linux_x86_trunk_release = {
	'name': 'linux_x86_trunk_release',
	'slavename': 'linux-x86',
	'builddir': 'linux_x86_trunk_release',
	'factory': linux_x86_trunk_release,
}

windows_x86_trunk_mingw_debug = factory.BuildFactory()
windows_x86_trunk_mingw_debug.addStep(svn_revert)
windows_x86_trunk_mingw_debug.addStep(checkout)
windows_x86_trunk_mingw_debug.addStep(configure('setenv_qt-4.5.1-mingw.bat & build_mingw-debug.bat'))
windows_x86_trunk_mingw_debug.addStep(compile('setenv_qt-4.5.1-mingw.bat & mingw32-make install'))
windows_x86_trunk_mingw_debug.addStep(create_nsis_setup('setenv_qt-4.5.1-mingw.bat & mingw32-make nsis'))
windows_x86_trunk_mingw_debug.addSteps(upload_package)
builder_windows_x86_trunk_mingw_debug = {
	'name': 'windows_x86_trunk_mingw_debug',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_mingw_debug',
	'factory': windows_x86_trunk_mingw_debug,
}

windows_x86_trunk_mingw_release = factory.BuildFactory()
windows_x86_trunk_mingw_release.addStep(cleanup('setenv_qt-4.5.1-mingw.bat & mingw32-make clean'))
windows_x86_trunk_mingw_release.addStep(svn_revert)
windows_x86_trunk_mingw_release.addStep(checkout)
windows_x86_trunk_mingw_release.addStep(configure('setenv_qt-4.5.1-mingw.bat & build_mingw-release.bat'))
windows_x86_trunk_mingw_release.addStep(compile('setenv_qt-4.5.1-mingw.bat & mingw32-make install'))
windows_x86_trunk_mingw_release.addStep(create_nsis_setup('setenv_qt-4.5.1-mingw.bat & mingw32-make nsis'))
windows_x86_trunk_mingw_release.addSteps(upload_package)
builder_windows_x86_trunk_mingw_release = {
	'name': 'windows_x86_trunk_mingw_release',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_mingw_release',
	'factory': windows_x86_trunk_mingw_release,
}

windows_x86_trunk_msvc71_debug = factory.BuildFactory()
windows_x86_trunk_msvc71_debug.addStep(svn_revert)
windows_x86_trunk_msvc71_debug.addStep(checkout)
windows_x86_trunk_msvc71_debug.addStep(configure('setenv_qt-4.5.0-msvc71.bat & build_nmake-debug.bat'))
windows_x86_trunk_msvc71_debug.addStep(compile('setenv_qt-4.5.0-msvc71.bat & nmake install'))
windows_x86_trunk_msvc71_debug.addStep(create_nsis_setup('setenv_qt-4.5.0-msvc71.bat & nmake nsis'))
windows_x86_trunk_msvc71_debug.addSteps(upload_package)
builder_windows_x86_trunk_msvc71_debug = {
	'name': 'windows_x86_trunk_msvc71_debug',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_msvc71_debug',
	'factory': windows_x86_trunk_msvc71_debug,
}

windows_x86_trunk_msvc71_release = factory.BuildFactory()
windows_x86_trunk_msvc71_release.addStep(cleanup('setenv_qt-4.5.0-msvc71.bat & nmake clean'))
windows_x86_trunk_msvc71_release.addStep(svn_revert)
windows_x86_trunk_msvc71_release.addStep(checkout)
windows_x86_trunk_msvc71_release.addStep(configure('setenv_qt-4.5.0-msvc71.bat & build_nmake-release.bat'))
windows_x86_trunk_msvc71_release.addStep(compile('setenv_qt-4.5.0-msvc71.bat & nmake install'))
windows_x86_trunk_msvc71_release.addStep(create_nsis_setup('setenv_qt-4.5.0-msvc71.bat & nmake nsis'))
windows_x86_trunk_msvc71_release.addSteps(upload_package)
builder_windows_x86_trunk_msvc71_release = {
	'name': 'windows_x86_trunk_msvc71_release',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_msvc71_release',
	'factory': windows_x86_trunk_msvc71_release,
}

windows_x86_trunk_msvc90_debug = factory.BuildFactory()
windows_x86_trunk_msvc90_debug.addStep(svn_revert)
windows_x86_trunk_msvc90_debug.addStep(checkout)
windows_x86_trunk_msvc90_debug.addStep(configure('setenv_qt-4.5.0-msvc90.bat & build_nmake-debug.bat'))
windows_x86_trunk_msvc90_debug.addStep(compile('setenv_qt-4.5.0-msvc90.bat & nmake install'))
windows_x86_trunk_msvc90_debug.addStep(create_nsis_setup('setenv_qt-4.5.0-msvc90.bat & nmake nsis'))
windows_x86_trunk_msvc90_debug.addSteps(upload_package)
builder_windows_x86_trunk_msvc90_debug = {
	'name': 'windows_x86_trunk_msvc90_debug',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_msvc90_debug',
	'factory': windows_x86_trunk_msvc90_debug,
}

windows_x86_trunk_msvc90_release = factory.BuildFactory()
windows_x86_trunk_msvc90_release.addStep(cleanup('setenv_qt-4.5.0-msvc90.bat & nmake clean'))
windows_x86_trunk_msvc90_release.addStep(svn_revert)
windows_x86_trunk_msvc90_release.addStep(checkout)
windows_x86_trunk_msvc90_release.addStep(configure('setenv_qt-4.5.0-msvc90.bat & build_nmake-release.bat'))
windows_x86_trunk_msvc90_release.addStep(compile('setenv_qt-4.5.0-msvc90.bat & nmake install'))
windows_x86_trunk_msvc90_release.addStep(create_nsis_setup('setenv_qt-4.5.0-msvc90.bat & nmake nsis'))
windows_x86_trunk_msvc90_release.addSteps(upload_package)
builder_windows_x86_trunk_msvc90_release = {
	'name': 'windows_x86_trunk_msvc90_release',
	'slavename': 'windows-x86',
	'builddir': 'windows_x86_trunk_msvc90_release',
	'factory': windows_x86_trunk_msvc90_release,
}

config['builders'] = [
	builder_linux_x86_trunk_debug,
	builder_linux_x86_trunk_release,
	builder_windows_x86_trunk_mingw_debug,
	builder_windows_x86_trunk_mingw_release,
	builder_windows_x86_trunk_msvc71_debug,
	builder_windows_x86_trunk_msvc71_release,
	builder_windows_x86_trunk_msvc90_debug,
	builder_windows_x86_trunk_msvc90_release
]


####### STATUS TARGETS

config['status'] = []

from buildbot.status import html
config['status'].append(html.WebStatus(http_port = 8010, allowForce = True))


####### PROJECT IDENTITY

config['projectName'] = 'QuarkPlayer'
config['projectURL'] = 'http://phonon-vlc-mplayer.googlecode.com/'
config['buildbotURL'] = 'http://localhost:8010/'
